<template>
  <div>
    <div
      class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
    >
      <div class="mui-scroll">
        <a
          :class="['mui-control-item', item.id === 0 ?  'mui-active' : ''] "
          v-for="item in shouList"
          :key="item.id"
          @tap="getPhotoListByCateId(item.id)"
        >{{item.title}}</a>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul class="phono-list">
      <router-link :to="'/home/photosIfon/' + item.id" v-for="item in list" :key="item.id" tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <h2 class="info-title">{{item.title}}</h2>
          <div class="info-body">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";
mui(".mui-scroll-wrapper").scroll({
  deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
});
export default {
  data() {
    return {
      shouList: [],
      list: []
    };
  },
  created() {
    this.getshouList();
    this.getPhotoListByCateId(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getshouList() {
      this.$http.get("api/getimgcategory").then(res => {
        var res = res.body;
        if (res.status === 0) {
          res.message.unshift({
            title: "全部",
            id: 0
          });
          this.shouList = res.message;
        } else {
          toast("获取失败");
        }
      });
    },
    getPhotoListByCateId(id) {
      this.$http.get("api/getimages/" + id).then(res => {
        var res = res.body;
        if (res.status === 0) {
          this.list = res.message;
        } else {
          toast("获取失败");
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
.phono-list {
  margin: 0;
  padding: 10px;
  margin-bottom: 0;
  li {
    background-color: #ccc;
    margin-bottom: 10px;
    text-align: center;
    list-style: none;
    box-shadow: 0 0 9px #999;
      position: relative;
    img {
      width: 100%;
     vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
  .info{
    bottom: 0;
    position: absolute;
    color: #fff;
    background-color: rgba(0,0,0,0.4);
    max-height: 84px;
      .info-title{
        font-size: 14px;
      }
    .info-body{
      font-size: 13px;
    }
  }
}
</style>